﻿using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
namespace Ecreate.Data.Hibernate
{
    public class WinStorage :ISessionStorage
    {
        [ThreadStatic]
        private static ISession m_Session;

        /**/
        /// <summary>
        ///获得Session 
        /// </summary>
        /// <returns></returns>
        public ISession Get()
        {
            if (m_Session != null)
            {
                if (!m_Session.IsConnected)
                {
                    m_Session.Reconnect();
                }
            }
            return m_Session;
        }

        /**/
        /// <summary>
        /// 保存Session
        /// </summary>
        /// <param name="value"></param>
        public void Set(ISession value)
        {
            if (value.IsConnected)
            {
                value.Disconnect();
            }
            m_Session = value;
        }

    }
}
